home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / ham / sattrk31.tgz / sattrack-3.1.tar / SatTrack / src / sattrack / satread.c < prev    next >
C/C++ Source or Header  |  1995-03-16  |  50KB  |  1,537 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*  Title       : satread.c                                                   */
  4. /*  Author      : Manfred Bester                                              */
  5. /*  Date        : 03Mar92                                                     */
  6. /*  Last change : 15Mar95                                                     */
  7. /*                                                                            */
  8. /*  Synopsis    : Routines for reading data from resource files and other     */
  9. /*                I/O functions.                                              */
  10. /*                                                                            */
  11. /*                                                                            */
  12. /*  Resources   : cities.dat, defaults.dat, modes.dat, satlist_nnn.dat,       */
  13. /*                tlex.dat                                                    */
  14. /*                                                                            */
  15. /*  cities.dat:      contains information on various gorund stations          */
  16. /*                   format: `name`,lat,long,alt                              */
  17. /*                                                                            */
  18. /*  defaults.dat:    contains default parameters                              */
  19. /*                                                                            */
  20. /*  modes.dat:       contains information on launch dates, frequencies,       */
  21. /*                   transmission modes, attitudes etc.                       */
  22. /*                                                                            */
  23. /*  satlist_nnn.dat: contains list of satellite names for multisat tracking   */
  24. /*                   display ('nnn' denotes the satellite group)              */
  25. /*                                                                            */
  26. /*  tle.dat:         contains NORAD two-line orbital element sets             */
  27. /*                   (also sts.dat, sts-55.dat, tvsat.dat, etc.)              */
  28. /*                                                                            */
  29. /*  tlex.dat:        contains concatenated NORAD/NASA two-line orbital        */
  30. /*                   element sets                                             */
  31. /*                                                                            */
  32. /*                                                                            */
  33. /*  SatTrack is Copyright (c) 1992, 1993, 1994, 1995 by Manfred Bester.       */
  34. /*  All Rights Reserved.                                                      */
  35. /*                                                                            */
  36. /*  Permission to use, copy, and distribute SatTrack and its documentation    */
  37. /*  in its entirety for educational, research and non-profit purposes,        */
  38. /*  without fee, and without a written agreement is hereby granted, provided  */
  39. /*  that the above copyright notice and the following three paragraphs appear */
  40. /*  in all copies. SatTrack may be modified for personal purposes, but        */
  41. /*  modified versions may NOT be distributed without prior consent of the     */
  42. /*  author.                                                                   */
  43. /*                                                                            */
  44. /*  Permission to incorporate this software into commercial products may be   */
  45. /*  obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,    */
  46. /*  Berkeley, CA 94709, USA. Note that distributing SatTrack 'bundled' in     */
  47. /*  with ANY product is considered to be a 'commercial purpose'.              */
  48. /*                                                                            */
  49. /*  IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, */
  50. /*  SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF   */
  51. /*  THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED  */
  52. /*  OF THE POSSIBILITY OF SUCH DAMAGE.                                        */
  53. /*                                                                            */
  54. /*  THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT      */
  55. /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A   */
  56. /*  PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"      */
  57. /*  BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, */
  58. /*  UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                  */
  59. /*                                                                            */
  60. /******************************************************************************/
  61.  
  62. #include <stdio.h>
  63. #include <math.h>
  64. #include <string.h>
  65.  
  66. #ifndef STDLIB
  67. #include <stdlib.h>
  68. #endif
  69.  
  70. #include "satglobalsx.h"
  71. #include "sattrack.h"
  72.  
  73. #ifdef HPTERM
  74. #include "hpterm.h"               /* definitions of hpterm macros             */
  75. #else
  76. #include "vt100.h"                /* definitions of VT100 macros              */
  77. #endif
  78.  
  79. /******************************************************************************/
  80. /*                                                                            */
  81. /* checkTimeZone: enter time zone                                             */
  82. /*                                                                            */
  83. /******************************************************************************/
  84.  
  85. void checkTimeZone()
  86.  
  87. {
  88.     if (timeZoneFlag)
  89.     {
  90.         nl();
  91.         printf("Time zone                      ");
  92.         printf("<%4s> : ",defTimeZoneStr);
  93.         mGets(timeZoneStr,80,stdin);
  94.         upperCase(timeZoneStr);
  95.  
  96.         if (!strlen(timeZoneStr))
  97.             strcpy(timeZoneStr,defTimeZoneStr);
  98.  
  99.         getTimeZone();
  100.         printf("Time zone set to %s (%+.2f h)\n",
  101.                 timeZoneStr,timeZone*24.0);
  102.     }
  103.  
  104.     if (batchModeFlag)
  105.     {
  106.         strcpy(timeZoneStr,batchTimeZone);
  107.         getTimeZone();
  108.     }
  109.  
  110.     return;
  111. }
  112.  
  113. /******************************************************************************/
  114. /*                                                                            */
  115. /* getTimeZone: gets time zone [h] from the time zone string information      */
  116. /*                                                                            */
  117. /******************************************************************************/
  118.  
  119. void getTimeZone()
  120.  
  121. {
  122.     int i;
  123.  
  124.     timeZone = 0.0;
  125.  
  126.     for (i = 0; i < timeZones; i++)
  127.     {
  128.         if (!strcmp(timeZoneList[i],timeZoneStr))
  129.             timeZone = timeZoneHour[i] / 24.0;          /* gets time zone [d] */
  130.     }
  131.  
  132.     if (fabs(timeZone) < ONEPPM)
  133.     {
  134.         if (strlen(timeZoneStr) && fabs((double) atof(timeZoneStr)) < 12.000001
  135.                                 && fabs((double) atof(timeZoneStr)) >  0.000001)
  136.         {
  137.             timeZone = (double) atof(timeZoneStr) / 24.0;
  138.             sprintf(timeZoneStr,"LOC");
  139.         }
  140.  
  141.         else
  142.             sprintf(timeZoneStr,"UTC");
  143.     }
  144.  
  145.     return;
  146. }
  147.  
  148. /******************************************************************************/
  149. /*                                                                            */
  150. /* getDefaultData: reads default parameters from 'defaults.dat'               */
  151. /*                                                                            */
  152. /******************************************************************************/
  153.  
  154. void getDefaultData()
  155.  
  156. {
  157.     char defLine[120];
  158.     FILE *defFile;
  159.  
  160.     if (defaultsFileFlag)
  161.         sprintf(defaultsDat,"%s/%s/defaults%d.dat",
  162.                 strpHome,DATA,defaultsFileNum);
  163.     else
  164.         sprintf(defaultsDat,"%s/%s/%s",strpHome,DATA,DEFAULTS);
  165.  
  166.     if ((defFile = fopen(defaultsDat,"r")) == NULL)
  167.     {
  168.         doBeep(); nl(); reverseBlink();
  169.         printf(" Cannot open input file '%s' \n",defaultsDat);
  170.         normal(); nl();
  171.         exit(-1);
  172.     }
  173.  
  174.     sprintf(defSite,"%s",DEFSITE);
  175.     sprintf(callSign,"%s",DEFCALLSIGN);
  176.     sprintf(defSat,"%s",DEFSAT);
  177.     sprintf(defSatGroup,"%s",DEFSATGROUP);
  178.     sprintf(defSetTLE,"%s",DEFSETTLE);
  179.     sprintf(defSetSTS,"%s",DEFSETSTS);
  180.     sprintf(defSetType,"%s",DEFSETTYPE);
  181.     sprintf(defDispType,"%s",DEFDISPTYPE);
  182.     sprintf(defTimeZoneStr,"%s",DEFTIMEZONE);
  183.     sprintf(antennaIO,"%s",DEFANTENNADEV);
  184.     sprintf(radioIOA,"%s",DEFRADIODEVA);
  185.     sprintf(radioIOB,"%s",DEFRADIODEVB);
  186.     sprintf(termTypeX,"%s",DEFXTERM);
  187.  
  188.     defDuration     = DEFDURATION;
  189.     defMinElevation = DEFMINELEVATION;
  190.     trackingFlag    = DEFTRACKINGFLAG;
  191.     numLines        = DEFDISPLINES;
  192.     numLinesX       = DEFXDISPLINES;
  193.     atmPressure     = DEFATMPRESS;
  194.     ambTemperature  = DEFAMBTEMP;
  195.     relHumidity     = DEFRELHUMID;
  196.  
  197.     while (fgets(defLine,100,defFile))
  198.     {
  199.         defLine[strlen(defLine) - 1] = '\0';
  200.         truncBlanks(defLine);
  201.  
  202.         if (!strncmp(defLine,"Site:",5))
  203.         {
  204.             clipString(defLine,5);
  205.             sprintf(defSite,"%s",defLine);
  206.         }
  207.  
  208.         if (!strncmp(defLine,"Call sign:",10))
  209.         {
  210.             clipString(defLine,10);
  211.             sprintf(callSign,"%s",defLine);
  212.         }
  213.  
  214.         if (!strncmp(defLine,"Satellite:",10))
  215.         {
  216.             clipString(defLine,10);
  217.             sprintf(defSat,"%s",defLine);
  218.         }
  219.  
  220.         sscanf(defLine,"Satellite group: %s",defSatGroup);
  221.         sscanf(defLine,"Element set TLE: %s",defSetTLE);
  222.         sscanf(defLine,"Element set STS: %s",defSetSTS);
  223.         sscanf(defLine,"Element set type: %s",defSetType);
  224.         sscanf(defLine,"Live display type: %s",defDispType);
  225.         sscanf(defLine,"Time zone: %s",defTimeZoneStr);
  226.         sscanf(defLine,"Duration: %lf",&defDuration);
  227.         sscanf(defLine,"Min elevation: %lf",&defMinElevation);
  228.         sscanf(defLine,"Tracking: %d",&trackingFlag);
  229.         sscanf(defLine,"Antenna: %s",antennaIO);
  230.         sscanf(defLine,"Radio A: %s",radioIOA);
  231.         sscanf(defLine,"Radio B: %s",radioIOB);
  232.         sscanf(defLine,"Display lines: %d",&numLines);
  233.         sscanf(defLine,"X display lines: %d",&numLinesX);
  234.         sscanf(defLine,"X terminal type: %s",termTypeX);
  235.         sscanf(defLine,"Pressure: %lf",&atmPressure);
  236.         sscanf(defLine,"Temperature: %lf",&ambTemperature);
  237.         sscanf(defLine,"Humidity: %lf",&relHumidity);
  238.     }
  239.  
  240.     upperCase(defDispType);
  241.  
  242.     strcpy(timeZoneStr,defTimeZoneStr);
  243.     getTimeZone();
  244.  
  245.     fclose(defFile);
  246.  
  247.     if (verboseFlag)
  248.     {
  249.         nl();
  250.         printf("Default parameters:\n\n");
  251.         printf("Ground station    : %20s\n",defSite);
  252.         printf("Call sign         : %20s\n",callSign);
  253.         printf("Satellite         : %20s\n",defSat);
  254.         printf("Element set TLE   : %20s\n",defSetTLE);
  255.         printf("Element set STS   : %20s\n",defSetSTS);
  256.         printf("Element set type  : %20s\n",defSetType);
  257.         printf("Live display type : %20s\n",defDispType);
  258.         printf("Satellite group   : %20s\n",defSatGroup);
  259.         printf("Time zone         : %20s (%+.1f h)\n",
  260.                 timeZoneStr,timeZone*24.0);
  261.         printf("Duration          : %20.1f d\n",defDuration);
  262.         printf("Min elevation     : %20.1f deg\n",defMinElevation);
  263.         printf("Tracking          : %20d\n",trackingFlag);
  264.         printf("Antenna interface : %20s\n",antennaIO);
  265.         printf("Radio interface A : %20s\n",radioIOA);
  266.         printf("Radio interface B : %20s\n",radioIOB);
  267.         printf("Display lines     : %20d\n",numLines);
  268.         printf("X display lines   : %20d\n",numLinesX);
  269.         printf("X terminal type   : %20s\n",termTypeX);
  270.         printf("Pressure          : %20.1f mmHg\n",atmPressure);
  271.         printf("Temperature       : %20.1f C\n",ambTemperature);
  272.         printf("Humidity          : %20.1f %%\n",relHumidity);
  273.         nl();
  274.     }
  275.  
  276.     return;
  277. }
  278.  
  279. /******************************************************************************/
  280. /*                                                                            */
  281. /* getSatFileName: gets reduced satellite name for creating output file, i.e. */
  282. /*                 replace blanks and "/" in file name with "_", delete "("   */
  283. /*                 and ")"                                                    */
  284. /*                                                                            */
  285. /******************************************************************************/
  286.  
  287. void getSatFileName()
  288.  
  289. {
  290.     int i, j;
  291.  
  292.     i = 0;
  293.     j = 0;
  294.  
  295.     do
  296.     {
  297.         if (satName[i] != ' ' && satName[i] != '(' &&
  298.             satName[i] != ')' && satName[i] != '"' &&
  299.             satName[i] != '/')
  300.         {
  301.             satFileName[j] = satName[i];
  302.             i++; j++;
  303.         }
  304.  
  305.         if (satName[i] == ' ' || satName[i] == '/')
  306.         {
  307.             satFileName[j] = '_';
  308.             i++; j++;
  309.         }
  310.  
  311.         if (satName[i] == '(' || satName[i] == ')' || satName[i] == '"')
  312.         {
  313.             i++;
  314.         }
  315.     }
  316.     while (satName[i] != '\0');
  317.  
  318.     satFileName[i] = '\0';
  319.     return;
  320. }
  321.  
  322. /******************************************************************************/
  323. /*                                                                            */
  324. /* getSatParams: reads satellite parameters from data file with the two-line  */
  325. /*               orbital element sets                                         */
  326. /*                                                                            */
  327. /******************************************************************************/
  328.  
  329. void getSatParams()
  330.  
  331. {
  332.     int    error, error1, firstTry;
  333.     char   str[80], stsName[20];
  334.  
  335.     error = TRUE;
  336.  
  337.     while (error)
  338.     {
  339.         if (batchModeFlag)
  340.             strcpy(satName,batchSatName);
  341.  
  342.         else
  343.         {
  344.             if (quickStartFlag)
  345.                 *satName = '\0';
  346.  
  347.             else
  348.             {
  349.                 printf("Satellite name <%20s> : ",defSat);
  350.                 mGets(satName,80,stdin);
  351.             }
  352.         }
  353.  
  354.         if (!strlen(satName))
  355.             sprintf(satName,"%s",defSat);
  356.  
  357.         cleanSatName(satName);
  358.         strcpy(stsName,satName);
  359.         upperCase(stsName);
  360.  
  361.         satTypeFlag = BASIC;
  362.  
  363.         if (!strncmp(stsName,"STS",3))
  364.             satTypeFlag = STS;
  365.  
  366.         if (!strncmp(stsName,"MIR",3) && (int) strlen(stsName) == 3)
  367.             satTypeFlag = MIR;
  368.  
  369.         sprintf(defSet,"%s",(satTypeFlag == STS) ? defSetSTS : defSetTLE);
  370.  
  371.         if (batchModeFlag)
  372.             strcpy(elementFile,batchTleFile);
  373.  
  374.         else
  375.         {
  376.             if (quickStartFlag)
  377.                 *elementFile = '\0';
  378.  
  379.             else
  380.             {
  381.                 printf("Two-line elements <%17s> : ",defSet);
  382.                 mGets(elementFile,80,stdin);
  383.             }
  384.         }
  385.  
  386.         if (!strlen(elementFile))
  387.             sprintf(elementFile,"%s",defSet);
  388.  
  389.         if (strcmp(TLEX,elementFile))
  390.         {
  391.             error = readTleFile(strpHome,elementFile,numTle);
  392.  
  393.             if (error)
  394.             {
  395.                 doBeep(); nl(); reverseBlink();
  396.                 printf(" File '%s' not found \n",elementFile);
  397.                 normal(); nl();
  398.  
  399.                 if (batchModeFlag || quickStartFlag)
  400.                     exit(-1);
  401.             }
  402.         }
  403.  
  404.         error = readTle(TRUE,satName,&satNum,&elementSet,
  405.                    &epochDay,&inclination,&epochRaan, &eccentricity,
  406.                    &epochArgPerigee,&epochMeanAnomaly,&epochMeanMotion,
  407.                    &decayRate,&decayRateDot,&bStarCoeff,
  408.                    &epochOrbitNum,&ephemerisType);
  409.  
  410.         if (error)
  411.         {
  412.             doBeep(); nl(); reverseBlink();
  413.  
  414.             if (error == 1 || error == 2)
  415.                 printf(" %s: check sum error in TLE set, line %d \n",
  416.                        satName,error);
  417.  
  418.             if (error == 3)
  419.                 printf(" %s: no matching satellite name or object number \n",
  420.                        satName);
  421.  
  422.             if (error == 4)
  423.                 printf(" Specify one satellite \n");
  424.  
  425.             normal(); nl();
  426.  
  427.             if (batchModeFlag || quickStartFlag)
  428.                 exit(-1);
  429.         }
  430.     }
  431.  
  432.     sprintf(defSat,"%ld",satNum);
  433.     strcpy(stsName,satName);
  434.     upperCase(stsName);
  435.  
  436.     satTypeFlag = BASIC;                               /* restore satTypeFlag */
  437.  
  438.     if (!strncmp(stsName,"STS",3))
  439.         satTypeFlag = STS;
  440.  
  441.     if (!strncmp(stsName,"MIR",3) && (int) strlen(stsName) == 3)
  442.         satTypeFlag = MIR;
  443.  
  444.     if (satTypeFlag == STS)
  445.     {
  446.         error1   = TRUE;
  447.         firstTry = TRUE;
  448.  
  449.         while (error1)
  450.         {
  451.             if (batchModeFlag)
  452.                 strcpy(elementType,batchTleType);
  453.  
  454.             else
  455.             {
  456.                 if (quickStartFlag)
  457.                     *elementType = '\0';
  458.  
  459.                 else
  460.                 {
  461.                     if (firstTry)
  462.                         printf("Element set type              ");
  463.                     else
  464.                         printf("Element set type (NASA,NORAD) ");
  465.  
  466.                     printf("<%5s> : ",defSetType);
  467.                     mGets(elementType,80,stdin);
  468.                     firstTry = FALSE;
  469.                 }
  470.             }
  471.  
  472.             if (!strlen(elementType))
  473.                 sprintf(elementType,"%s",defSetType);
  474.             else
  475.                 upperCase(elementType);
  476.  
  477.             error1 = (!strcmp(elementType,"NASA") || 
  478.                       !strcmp(elementType,"NORAD")) ? FALSE : TRUE;
  479.  
  480.             if ((batchModeFlag || quickStartFlag) && error1)
  481.             {
  482.                 doBeep(); nl(); reverseBlink();
  483.                 printf(" Type of element set specified incorrectly \n");
  484.                 normal(); nl();
  485.                 exit(-1);
  486.             }
  487.  
  488.             if (!batchModeFlag && !quickStartFlag && error1)
  489.                 doBeep();
  490.         }
  491.     }
  492.  
  493.     else
  494.         sprintf(elementType,"%s",defSetType);
  495.  
  496.     getSatFileName();                                   /* remove blanks etc. */
  497.     changeElementUnits();
  498.     checkPropModelType();
  499.  
  500.     if (realTime-elsetEpoch > 0.0)
  501.         sprintf(updateString,"%.1f days ago",realTime-elsetEpoch);
  502.     else
  503.         sprintf(updateString,"%.1f days ahead",elsetEpoch-realTime);
  504.  
  505.     if (verboseFlag)
  506.     {
  507.         printElements();
  508.  
  509.         if (geoSyncFlag)
  510.         {
  511.             if (geoSyncFlag == GEOSYNC)
  512.                 printf("Geosynchronous satellite\n");
  513.             else
  514.                 printf("Geostationary satellite\n");
  515.  
  516.             nl();
  517.         }
  518.  
  519.         if (satCrashFlag)
  520.         {
  521.             reverseBlink();
  522.  
  523.             if (satCrashFlag)
  524.                 printf(" Satellite has crashed already \n");
  525.  
  526.             normal();
  527.             nl();
  528.         }
  529.     }
  530.  
  531.     else
  532.     {
  533.         if (!batchModeFlag && !quickStartFlag)
  534.         {
  535.             sprintf(str,"%ld, %s",satNum,satName);
  536.             printf("Last update for %-21s : ",str);
  537.             printf("%s (#%d, Orbit %ld)\n\n",
  538.                     updateString,elementSet,epochOrbitNum);
  539.         }
  540.     }
  541.  
  542.     return;
  543. }
  544.  
  545. /******************************************************************************/
  546. /*                                                                            */
  547. /* changeElementUnits: changes units of Keplerian elements etc.               */
  548. /*                                                                            */
  549. /******************************************************************************/
  550.  
  551. void changeElementUnits()
  552.  
  553. {
  554.     double epochDayTime, epochH, epochM, epochS, epochSec;
  555.     int    epochYear, epochMonth, epochMonthDay, epochD, epochHour, epochMin;
  556.  
  557.     elsetEpochDay = epochDay;
  558.     epochYear     = (int) (epochDay  / 1000.0);
  559.     epochDay     -= (double) epochYear * 1000.0;
  560.     elsetEpoch    = epochDay + (double) getDayNum(0,1,epochYear);
  561.     epochD        = (int) epochDay;
  562.     epochDayTime  = epochDay - (double) epochD;
  563.     epochDay     += (double) getDayNum(0,1,epochYear);
  564.  
  565.     epochH        = 24.0 * epochDayTime;
  566.     epochM        = 60.0 * modf(epochH,&epochH);
  567.     epochS        = 60.0 * modf(epochM,&epochM);
  568.  
  569.     if (fabs(epochS - 60.0) < 5.0e-4)
  570.     {
  571.         epochS  = 0.0;
  572.         epochM += 1.0;
  573.  
  574.         if (fabs(epochM - 60.0) < 1.0e-4)
  575.         {
  576.             epochM  = 0.0;
  577.             epochH += 1.0;
  578.  
  579.             if (fabs(epochH - 24.0) < 1.0e-4)
  580.             {
  581.                 epochH  = 0.0;
  582.                 epochD += 1;
  583.             }
  584.         }
  585.     }
  586.  
  587.     epochHour = (int) epochH;
  588.     epochMin  = (int) epochM;
  589.     epochSec  = epochS;
  590.  
  591.     calendar(epochYear,epochD,&epochMonth,&epochMonthDay);
  592.  
  593.     sprintf(epochString,"%02d%3s%02d  %02d:%02d:%06.3f UTC",
  594.             epochMonthDay,monthName(epochMonth),epochYear,
  595.             epochHour,epochMin,epochSec);
  596.  
  597.     inclination      *= CDR;
  598.     epochRaan        *= CDR;
  599.     epochArgPerigee  *= CDR;
  600.     epochMeanAnomaly *= CDR;
  601.  
  602.     cosInclination    = cos(inclination);
  603.     sinInclination    = sin(inclination);
  604.  
  605.     geoSyncFlag = (fabs(epochMeanMotion - 1.0) < GEOSYNCMOT) ? GEOSYNC : FALSE;
  606.  
  607.     if (geoSyncFlag)
  608.         geoSyncFlag = (fabs(inclination) < GEOSTATINC) ? GEOSTAT : GEOSYNC;
  609.  
  610.     return;
  611. }
  612.  
  613. /******************************************************************************/
  614. /*                                                                            */
  615. /* getSatModes: reads modes of the specified satellite                        */
  616. /*                                                                            */
  617. /******************************************************************************/
  618.  
  619. void getSatModes(satelliteName)
  620.  
  621. char *satelliteName;
  622.  
  623. {
  624.     double cosAttLat, sinAttLat, cosAttLong, sinAttLong;
  625.     long   objNum, objNumber;
  626.     int    readLines, foundSat, foundMode, gotMode;
  627.     char   str[40], strSat[120], modeLine[120], lDate[12];
  628.     FILE   *modeFile;
  629.  
  630.     foundSat     = FALSE;
  631.     foundMode    = FALSE;
  632.     gotMode      = FALSE;
  633.     launchFlag   = FALSE;
  634.     launchEpoch  = 0.0;
  635.     attitudeFlag = FALSE;
  636.     attLat       = 0.0;
  637.     attLong      = 0.0;
  638.     perigeePhase = 0.0;
  639.     maxPhase     = MAXPHASE;
  640.     numFreqs     = 0;
  641.     numModes     = 0;
  642.     objNum       = 0L;
  643.     readLines    = 0;
  644.  
  645.     *fullSatAlias = '\0';
  646.     *satAlias     = '\0';
  647.     sprintf(modesDat,"%s/%s/%s",strpHome,DATA,MODES);
  648.     sprintf(str,"%s",satelliteName);
  649.     objNumber = atol(str);
  650.  
  651.     if ((modeFile = fopen(modesDat,"r")) != NULL)
  652.     {
  653.         while (fgets(modeLine,100,modeFile) && !gotMode)
  654.         {
  655.             modeLine[strlen(modeLine) - 1] = '\0';
  656.             truncBlanks(modeLine);
  657.  
  658.             if (!foundMode)
  659.             {
  660.                 if (!strncmp(modeLine,"Satellite:",10))
  661.                 {
  662.                     clipString(modeLine,10);
  663.                     sprintf(strSat,"%s",modeLine);
  664.                 }
  665.  
  666.                 if (!strncmp(modeLine,"Object:",7))
  667.                 {
  668.                     clipString(modeLine,7);
  669.                     sscanf(modeLine,"%ld",&objNum);
  670.                 }
  671.  
  672.                 if (!strncmp(str,strSat,strlen(strSat)) || 
  673.                     objNum == objNumber)
  674.                 {
  675.                     readLines++;
  676.  
  677.                     if (objNum != objNumber)
  678.                         readLines = 2;
  679.  
  680.                     foundSat = TRUE;
  681.                 }
  682.  
  683.                 if (foundSat && readLines == 2)
  684.                     foundMode = TRUE;
  685.             }
  686.  
  687.             if (foundMode)
  688.             {
  689.                 if (!strncmp(modeLine,"Alias:",6))
  690.                 {
  691.                     clipString(modeLine,6);
  692.                     sprintf(fullSatAlias,"%s",modeLine);
  693.                     strncpy(satAlias,fullSatAlias,15);
  694.  
  695.                     if (verboseFlag)
  696.                         printf("Alias name        : %s\n",fullSatAlias);
  697.                 }
  698.  
  699.                 if (!strncmp(modeLine,"Launch:",7))
  700.                 {
  701.                     clipString(modeLine,7);
  702.                     sscanf(modeLine,"%s %d:%d:%d",
  703.                         lDate,&launchHour,&launchMin,&launchSec);
  704.  
  705.                     sprintf(launchString,"%s  %02d:%02d:%02d.000 UTC",
  706.                         lDate,launchHour,launchMin,launchSec);
  707.  
  708.                     dummyi = decodeDate(lDate,
  709.                                  &launchDay,&launchMonth,&launchYear);
  710.  
  711.                     launchFlag = TRUE;
  712.  
  713.                     if (verboseFlag)
  714.                         printf("Launch date/time  : %s\n",launchString);
  715.                 }
  716.  
  717.                 if (!strncmp(modeLine,"Attitude:",9))
  718.                 {
  719.                     clipString(modeLine,9);
  720.                     sscanf(modeLine,"%lf %lf",&attLong,&attLat);
  721.                     attitudeFlag = TRUE;
  722.  
  723.                     if (verboseFlag)
  724.                     {
  725.                         printf("Attitude          : ");
  726.                         printf("%.3f %.3f deg\n",attLong,attLat);
  727.                     }
  728.                 }
  729.  
  730.                 if (!strncmp(modeLine,"Frequency:",10) && numFreqs < MAXFREQS)
  731.                 {
  732.                     clipString(modeLine,10);
  733.  
  734.                     sscanf(modeLine,"%s %s %lf %lf %lf %lf",
  735.                         freqs[numFreqs].downlinkMode,
  736.                         freqs[numFreqs].uplinkMode,
  737.                         &freqs[numFreqs].downlink,
  738.                         &freqs[numFreqs].uplink,
  739.                         &freqs[numFreqs].bandwidth,
  740.                         &freqs[numFreqs].sign);
  741.  
  742.                     if (verboseFlag)
  743.                     {
  744.                         printf("Frequency #%-2d     : ",numFreqs+1);
  745.                         printf("%-4s %-4s %10.4f %10.4f %6.1f %3.0f\n",
  746.                             freqs[numFreqs].downlinkMode,
  747.                             freqs[numFreqs].uplinkMode,
  748.                             freqs[numFreqs].downlink,
  749.                             freqs[numFreqs].uplink,
  750.                             freqs[numFreqs].bandwidth,
  751.                             freqs[numFreqs].sign);
  752.                     }
  753.  
  754.                     freqs[numFreqs].downlink  *= CMHZHZ;
  755.                     freqs[numFreqs].uplink    *= CMHZHZ;
  756.                     freqs[numFreqs].bandwidth *= CKHZHZ;
  757.                     numFreqs++;
  758.                 }
  759.  
  760.                 if (!strncmp(modeLine,"Perigee phase:",14))
  761.                 {
  762.                     clipString(modeLine,14);
  763.                     sscanf(modeLine,"%lf",&perigeePhase);
  764.  
  765.                     if (verboseFlag)
  766.                         printf("Perigee phase     : %.6f MHz\n",perigeePhase);
  767.                 }
  768.  
  769.                 if (!strncmp(modeLine,"Max phase:",10))
  770.                 {
  771.                     clipString(modeLine,10);
  772.                     sscanf(modeLine,"%lf",&maxPhase);
  773.  
  774.                     if (verboseFlag)
  775.                         printf("Max phase         : %.6f\n",maxPhase);
  776.                 }
  777.  
  778.                 if (!strncmp(modeLine,"Mode:",5) && numModes < MAXMODES)
  779.                 {
  780.                     clipString(modeLine,5);
  781.  
  782.                     sscanf(modeLine,"%s %lf - %lf",
  783.                         modes[numModes].modeStr,
  784.                         &modes[numModes].minPhase,
  785.                         &modes[numModes].maxPhase);
  786.  
  787.                     if (verboseFlag)
  788.                     {
  789.                         printf("Mode              : %-2s  %3.0f - %3.0f\n",
  790.                         modes[numModes].modeStr,
  791.                         modes[numModes].minPhase,
  792.                         modes[numModes].maxPhase);
  793.                     }
  794.  
  795.                     numModes++;
  796.                 }
  797.  
  798.                 if (strlen(modeLine) <= 2)
  799.                     gotMode = TRUE;
  800.             }
  801.         }
  802.  
  803.         fclose(modeFile);
  804.  
  805.         if (verboseFlag) nl();
  806.  
  807.         if (launchFlag)
  808.         {
  809.             launchDate  = getDayNum(launchDay,launchMonth,launchYear);
  810.             launchTime  = (double) (launchHour+launchMin/60.0+launchSec/3600.0);
  811.             launchEpoch = (double) launchDate + launchTime/24.0;
  812.         }
  813.  
  814.         if (attitudeFlag)
  815.         {
  816.             attLat     *= CDR;
  817.             attLong    *= CDR;
  818.  
  819.             cosAttLat   = cos(attLat);
  820.             sinAttLat   = sin(attLat);
  821.             cosAttLong  = cos(attLong);
  822.             sinAttLong  = sin(attLong);
  823.  
  824.             satAttGl[0] = cosAttLong * cosAttLat;
  825.             satAttGl[1] = sinAttLong * cosAttLat;
  826.             satAttGl[2] = sinAttLat;
  827.         }
  828.     }
  829.  
  830.     if (numFreqs)
  831.     {
  832.         strcpy(downlinkMode,freqs[0].downlinkMode);
  833.         strcpy(uplinkMode,freqs[0].uplinkMode);
  834.         downlinkFreq     = freqs[0].downlink;
  835.         uplinkFreq       = freqs[0].uplink;
  836.         xponderBandwidth = freqs[0].bandwidth;
  837.         xponderSign      = freqs[0].sign;
  838.     }
  839.  
  840.     else
  841.     {
  842.         strcpy(downlinkMode,"FM");
  843.         strcpy(uplinkMode,"NONE");
  844.         downlinkFreq     = DOWNLINKFREQ * CMHZHZ;
  845.         uplinkFreq       = UPLINKFREQ * CMHZHZ;
  846.         xponderBandwidth = ZERO;
  847.         xponderSign      = ZERO;
  848.     }
  849.  
  850.     return;
  851. }
  852.  
  853. /******************************************************************************/
  854. /*                                                                            */
  855. /* getSiteParams: reads site parameters from input file 'cities.dat'          */
  856. /*                                                                            */
  857. /******************************************************************************/
  858.  
  859. void getSiteParams()
  860.  
  861. {
  862.     double cosSiteLat, sinSiteLat, cosSiteLng, sinSiteLng;
  863.     double sqf, a, c, s, h;
  864.     int    i, k, error, siteNameLen, foundSite;
  865.     char   siteNameStr[80], saveStr[80], ctyStr[80], str[80];
  866.  
  867.     maidenHeadFlag = FALSE;
  868.     foundSite      = FALSE;
  869.  
  870.     while (!foundSite)
  871.     {
  872.         if (batchModeFlag)
  873.             strcpy(siteNameStr,batchSiteName);
  874.  
  875.         else
  876.         {
  877.             if (quickStartFlag)
  878.                 *siteNameStr = '\0';
  879.  
  880.             else
  881.             {
  882.                 nl();
  883.                 printf("Ground station <%20s> : ",defSite);
  884.                 mGets(siteNameStr,80,stdin);
  885.             }
  886.         }
  887.  
  888.         if (!strlen(siteNameStr))
  889.             sprintf(siteNameStr,"%s",defSite);
  890.  
  891.         upperCase(siteNameStr);
  892.         siteNameLen = strlen(siteNameStr);
  893.  
  894.         k = 0;
  895.  
  896.         for (i = 0; i < numCities; i++)        /* check for ambiguous entries */
  897.         {
  898.             if (k == 1)
  899.                 strcpy(saveStr,ctyStr);
  900.  
  901.             strcpy(str,city[i].cty);
  902.             upperCase(str);
  903.  
  904.             if (!strncmp(siteNameStr,str, (unsigned int) siteNameLen))
  905.             {
  906.                 strcpy(ctyStr,city[i].cty);
  907.  
  908.                 if (k == 1)
  909.                     printf("\n%s\n",saveStr);
  910.  
  911.                 if (k >= 1)
  912.                     printf("%s\n",city[i].cty);
  913.  
  914.                 k++;
  915.             }
  916.         }
  917.  
  918.         i = 0;
  919.  
  920.         do
  921.         {
  922.             strcpy(str,city[i].cty);
  923.             upperCase(str);
  924.  
  925.             if (k == 1 && !strncmp(str,siteNameStr, (unsigned int) siteNameLen))
  926.             {
  927.                 foundSite = TRUE;
  928.  
  929.                 strcpy(fullSiteName,city[i].cty);
  930.                 strncpy(siteName,city[i].cty,15);
  931.                 shortString(siteName,fullSiteName,15);
  932.  
  933.                 siteLat  = city[i].lat;               /* geodetic location    */
  934.                 siteLong = city[i].lng;
  935.                 siteAlt  = city[i].alt * CMKM;
  936.  
  937.                 getMaidenHead(siteLat,siteLong,maidenHead);
  938.             }
  939.  
  940.             i++;
  941.         }
  942.         while (i < numCities && !foundSite);
  943.  
  944.         if (!foundSite)
  945.         {
  946.             error = getPosFromMaidenHead(siteNameStr,&siteLat,&siteLong);
  947.  
  948.             if (error)
  949.             {
  950.                 doBeep(); nl(); reverseBlink();
  951.  
  952.                 if (k == 0)
  953.                     printf(" %s: no matching ground station or locator error ",
  954.                         siteNameStr);
  955.                 else
  956.                     printf(" Specify one ground station ");
  957.  
  958.                 normal(); nl();
  959.  
  960.                 if (batchModeFlag || quickStartFlag)
  961.                 {
  962.                     nl(); exit(-1);
  963.                 }
  964.             }
  965.  
  966.             else
  967.             {
  968.                 maidenHeadFlag = TRUE;
  969.                 foundSite      = TRUE;
  970.                 strcpy(siteName,siteNameStr);
  971.                 strcpy(fullSiteName,siteNameStr);
  972.                 strcpy(siteNameID,siteNameStr);
  973.                 *maidenHead = '\0';
  974.                 siteAlt = 0.0;
  975.  
  976.                 getGroundTrack(siteLat,siteLong,
  977.                     &dummyd,&dummyd,&gndTrkDist,gndTrkDir,gndTrkCity);
  978.  
  979.                 if (!batchModeFlag)
  980.                     printf("%s is %.1f km %s of %s\n\n",
  981.                         siteName,gndTrkDist,gndTrkDir,gndTrkCity);
  982.             }
  983.         }
  984.     }
  985.  
  986.     if (!maidenHeadFlag)
  987.     {
  988.         strcpy(siteNameID,fullSiteName);
  989.         getSiteNameID(siteNameID);
  990.     }
  991.  
  992.     groundStation[0].ltd = siteLat;
  993.     groundStation[0].lng = siteLong;
  994.     strcpy(groundStation[0].gndStnID,siteNameID);
  995.  
  996.     if (verboseFlag)
  997.     {
  998.         nl();
  999.         printf("Ground station    : %20s\n",fullSiteName);
  1000.         printf("Latitude          : %20.6f deg ",fabs(siteLat*CRD));
  1001.  
  1002.         (siteLat >= 0.0) ? printf("N\n") : printf("S\n");
  1003.  
  1004.         printf("Longitude         : %20.6f deg ",fabs(siteLong*CRD));
  1005.  
  1006.         (siteLong >= 0.0) ? printf("W\n") : printf("E\n");
  1007.  
  1008.         printf("Altitude          : %20.6f m\n",siteAlt/CMKM);
  1009.         printf("Maidenhead locator: %20s\n",maidenHead);
  1010.         nl();
  1011.     }
  1012.  
  1013.     else
  1014.     {
  1015.         if (!batchModeFlag && !quickStartFlag && !maidenHeadFlag && 
  1016.             strcmp(fullSiteName,defSite))
  1017.             printf("%-38s: %s\n\n",fullSiteName,maidenHead);
  1018.     }
  1019.  
  1020.     /* now calculate the site vector in geocentric coordinates */
  1021.     /* this is needed only for the squint angle calculations   */
  1022.  
  1023.     cosSiteLat = cos(siteLat);
  1024.     sinSiteLat = sin(siteLat);
  1025.     cosSiteLng = cos(siteLong);
  1026.     sinSiteLng = sin(siteLong);
  1027.  
  1028.     sqf = SQR(1.0 - EARTHFLAT);
  1029.     a   = EARTHRADIUS;
  1030.     c   = 1.0 / sqrt(SQR(cosSiteLat) + sqf * SQR(sinSiteLat));
  1031.     s   = sqf * c;
  1032.     h   = siteAlt * CMKM;
  1033.  
  1034.     siteVecGl[0] = (a*c + h) * cosSiteLat * cosSiteLng;
  1035.     siteVecGl[1] = (a*c + h) * cosSiteLat * sinSiteLng;
  1036.     siteVecGl[2] = (a*s + h) * sinSiteLat;
  1037.  
  1038.     return;
  1039. }
  1040.  
  1041. /******************************************************************************/
  1042. /*                                                                            */
  1043. /* getTimeParams: reads additional parameters for orbit calculations          */
  1044. /*                                                                            */
  1045. /******************************************************************************/
  1046.  
  1047. void getTimeParams(timeArg)
  1048.  
  1049. double timeArg;
  1050.  
  1051. {
  1052.     double hour;
  1053.     long   sysDayNum;
  1054.     int    sysYear, sysMonth, sysDay, sysYearDay, sysHour, sysMin, sysSec;
  1055.     int    error;
  1056.     char   sysDate[20], sysTime[20];
  1057.  
  1058.     timeArg  += timeZone;
  1059.     sysDayNum = (long) timeArg;
  1060.     convertTime(timeArg,&dummyi,&sysHour,&sysMin,&sysSec);
  1061.     getDate(sysDayNum,&sysYear,&sysMonth,&sysDay,&sysYearDay);
  1062.     sprintf(sysDate,"%02d%3s%02d",sysDay,monthName(sysMonth),sysYear%100);
  1063.     sprintf(sysTime,"%02d:%02d:%02d",sysHour,sysMin,sysSec);
  1064.  
  1065.     if (batchModeFlag)
  1066.     {
  1067.         if (!strcmp(batchStartDate,NOW))
  1068.             strcpy(dispStr,YES);
  1069.     }
  1070.  
  1071.     else
  1072.     {
  1073.         printf("Start time  %7s %8s %-4s <Y> ? ",sysDate,sysTime,timeZoneStr);
  1074.  
  1075.         mGets(dispStr,80,stdin);
  1076.         upperCase(dispStr);
  1077.     }
  1078.  
  1079.     if (strlen(dispStr) && strncmp(dispStr,YES,1))
  1080.     {
  1081.         error = TRUE;
  1082.  
  1083.         while(error)
  1084.         {
  1085.             if (batchModeFlag)
  1086.                 strcpy(dispStr,batchStartDate);
  1087.  
  1088.             else
  1089.             {
  1090.                 printf("Start date (%-4s)           <%7s> : ",
  1091.                     timeZoneStr,sysDate);
  1092.                 mGets(dispStr,80,stdin);
  1093.  
  1094.                 if (!strlen(dispStr))
  1095.                     sprintf(dispStr,"%s",sysDate);
  1096.             }
  1097.  
  1098.             error = decodeDate(dispStr,&sysDay,&sysMonth,&sysYear);
  1099.  
  1100.             if (error) doBeep();
  1101.         }
  1102.  
  1103.         error = TRUE;
  1104.  
  1105.         while(error)
  1106.         {
  1107.             if (batchModeFlag)
  1108.                 strcpy(dispStr,batchStartTime);
  1109.  
  1110.             else
  1111.             {
  1112.                 printf("Start time (%-4s)          <%8s> : ",
  1113.                     timeZoneStr,sysTime);
  1114.                 mGets(dispStr,80,stdin);
  1115.  
  1116.                 if (!strlen(dispStr))
  1117.                     sprintf(dispStr,"%s",sysTime);
  1118.             }
  1119.  
  1120.             error = decodeTime(dispStr,&sysHour,&sysMin,&sysSec);
  1121.  
  1122.             if (error) doBeep();
  1123.         }
  1124.     }
  1125.  
  1126.     defStepTime = 1.0 / epochMeanMotion * SPD / 125.0;
  1127.     defStepTime = (double) (((int) (defStepTime / 10.0)) * 5.0);
  1128.  
  1129.     if (!shortPredFlag)
  1130.     {
  1131.         if (sunTransitFlag)
  1132.             stepTime = 0.25;
  1133.  
  1134.         else
  1135.         {
  1136.             if (batchModeFlag)
  1137.             {
  1138.                 if (!strcmp(batchStepTime,AUTO))
  1139.                     *dispStr = '\0';
  1140.                 else
  1141.                     strcpy(dispStr,batchStepTime);
  1142.             }
  1143.  
  1144.             else
  1145.             {
  1146.                 printf("Time step [s]                 <%5.0f> : ",defStepTime);
  1147.                 mGets(dispStr,80,stdin);
  1148.             }
  1149.  
  1150.             stepTime = (!strlen(dispStr)) ? defStepTime : atof(dispStr);
  1151.         }
  1152.     }
  1153.  
  1154.     if (batchModeFlag)
  1155.         strcpy(dispStr,batchDuration);
  1156.  
  1157.     else
  1158.     {
  1159.         printf("Duration [d]                   <%4.1f> : ",defDuration);
  1160.         mGets(dispStr,80,stdin);
  1161.     }
  1162.  
  1163.     duration   = (!strlen(dispStr)) ? defDuration : atof(dispStr);
  1164.     startTime  = (double) getDayNum(sysDay,sysMonth,sysYear);          /* [d] */
  1165.     hour       = (double) (sysHour + sysMin/60.0 + sysSec/3600.0);     /* [h] */
  1166.     startTime += hour / 24.0 - timeZone;
  1167.     stepTime  /= SPD;                                                  /* [d] */
  1168.     stopTime   = startTime + duration;                                 /* [d] */
  1169.  
  1170.     if (!shortPredFlag)
  1171.     {
  1172.         if (sunTransitFlag)
  1173.             minElevation = 0.0;
  1174.  
  1175.         else
  1176.         {
  1177.             if (batchModeFlag)
  1178.                 strcpy(dispStr,batchMinElev);
  1179.  
  1180.             else
  1181.             {
  1182.                 printf("Minimum elevation [deg]        ");
  1183.                 printf("<%4.1f> : ",defMinElevation);
  1184.                 mGets(dispStr,80,stdin);
  1185.             }
  1186.  
  1187.             minElevation = (!strlen(dispStr)) ? defMinElevation : atof(dispStr);
  1188.             minElevation *= CDR;
  1189.         }
  1190.     }
  1191.  
  1192.     return;
  1193. }
  1194.  
  1195. /******************************************************************************/
  1196. /*                                                                            */
  1197. /* printMode: prints phase-dependent mode of satellite into output file       */
  1198. /*                                                                            */
  1199. /******************************************************************************/
  1200.  
  1201. void printMode(outFile)
  1202.  
  1203. FILE *outFile;
  1204.  
  1205. {
  1206.     getMode();
  1207.     fprintf(outFile," %2s",modeString);
  1208.     return;
  1209. }
  1210.  
  1211. /******************************************************************************/
  1212. /*                                                                            */
  1213. /*  readSatList: reads names of satellites from the input file                */
  1214. /*                                                                            */
  1215. /******************************************************************************/
  1216.  
  1217. void readSatList()
  1218.  
  1219. {
  1220.     int  i, j, error, foundSat;
  1221.     char data[80], satListName[80], satListFileName[80], inputFileName[120];
  1222.     char str1[80], str2[80];
  1223.     FILE *inputFile;
  1224.  
  1225.     error = TRUE;
  1226.  
  1227.     while (error)
  1228.     {
  1229.         if (quickStartFlag)
  1230.             *satGroup = '\0';
  1231.  
  1232.         else
  1233.         {
  1234.             printf("Enter satellite group    <%10s> : ",defSatGroup);
  1235.             mGets(satGroup,80,stdin);
  1236.         }
  1237.  
  1238.         if (!strlen(satGroup))
  1239.             sprintf(satGroup,"%s",defSatGroup);
  1240.  
  1241.         lowerCase(satGroup);
  1242.         sprintf(data,"%s/%s",strpHome,DATA);
  1243.         sprintf(satListFileName,"satlist_%s.dat",satGroup);
  1244.         sprintf(inputFileName,"%s/%s",data,satListFileName);
  1245.  
  1246.         if ((inputFile = fopen(inputFileName,"r")) == NULL)
  1247.         {
  1248.             doBeep(); nl(); reverseBlink();
  1249.             printf(" File '%s' not found \n",satListFileName);
  1250.             normal(); nl();
  1251.             error = TRUE;
  1252.             fclose(inputFile);
  1253.  
  1254.             if (quickStartFlag)
  1255.                 exit(-1);
  1256.         }
  1257.  
  1258.         else
  1259.             error = FALSE;
  1260.     }
  1261.  
  1262.     if (!quickStartFlag)
  1263.         printf("\nreading satellite names for group '%s' ...\n",satGroup);
  1264.  
  1265.     upperCase(satGroup);
  1266.  
  1267.     i = 0;
  1268.  
  1269.     while (fgets(satListName,80,inputFile))
  1270.     {
  1271.         satListName[strlen(satListName) - 1] = '\0';
  1272.         truncBlanks(satListName);
  1273.         foundSat = FALSE;
  1274.  
  1275.         for (j = 0; j < i; j++)                 /* filter out duplicate names */
  1276.         {
  1277.             strcpy(str1,satel[j].satelName);
  1278.             strcpy(str2,satListName);
  1279.             upperCase(str1);
  1280.             upperCase(str2);
  1281.  
  1282.             if (!strcmp(str1,str2))
  1283.             {
  1284.                 printf("duplicate entry: %s\n",str1);
  1285.                 foundSat = TRUE;
  1286.             }
  1287.         }
  1288.  
  1289.         if (!foundSat)
  1290.         {
  1291.             cleanSatName(satListName);
  1292.             strcpy(satel[i].satelName,satListName);
  1293.             i++;
  1294.         }
  1295.     }
  1296.  
  1297.     fclose(inputFile);
  1298.     numSats  = i;
  1299.     foundSat = FALSE;
  1300.  
  1301.     for (i = 0; i < numSats; i++)             /* check if menu sat is in list */
  1302.     {
  1303.         if (!strncmp(satName,satel[i].satelName,strlen(satel[i].satelName)) || 
  1304.              satNum == atol(satel[i].satelName))
  1305.             foundSat = TRUE;
  1306.     }
  1307.  
  1308.     if (!foundSat)                            /* if not, add menu sat to list */
  1309.     {
  1310.         sprintf(satel[numSats].satelName,"%ld",satNum);
  1311.         numSats++;
  1312.     }
  1313.  
  1314.     return;
  1315. }
  1316.  
  1317. /******************************************************************************/
  1318. /*                                                                            */
  1319. /* saveSatElements: saves all Keplerian elements and other parameters in a    */
  1320. /*                  structure                                                 */
  1321. /*                                                                            */
  1322. /******************************************************************************/
  1323.  
  1324. void saveSatElements()
  1325.  
  1326. {
  1327.     int  i, j, n, error, grandError;
  1328.     long satNumSelect;
  1329.     char str[80], stsStr[80];
  1330.  
  1331.     grandError   = FALSE;
  1332.     satNumSelect = satNum;
  1333.     n = 0;
  1334.  
  1335.     if (!quickStartFlag)
  1336.         printf("loading element sets for %d satellites ...\n",numSats);
  1337.  
  1338.     for (i = 0; i < numSats; i++)
  1339.     {
  1340.         strcpy(str,satel[i].satelName);
  1341.         strcpy(stsStr,str);
  1342.         upperCase(stsStr);
  1343.  
  1344.         satTypeFlag = BASIC;                           /* restore satTypeFlag */
  1345.  
  1346.         if (!strncmp(stsStr,"STS",3))
  1347.             satTypeFlag = STS;
  1348.  
  1349.         if (!strncmp(stsStr,"MIR",3) && (int) strlen(stsStr) == 3)
  1350.             satTypeFlag = MIR;
  1351.  
  1352.         if (satTypeFlag == STS && !strcmp(str,satName))
  1353.             sprintf(elementFile,"%s",defSetSTS);
  1354.         else
  1355.             sprintf(elementFile,"%s",defSetTLE);
  1356.  
  1357.         error = readTle(FALSE,str,&satNum,&elementSet,
  1358.                    &epochDay,&inclination,&epochRaan,&eccentricity,
  1359.                    &epochArgPerigee,&epochMeanAnomaly,&epochMeanMotion,
  1360.                    &decayRate,&decayRateDot,&bStarCoeff,
  1361.                    &epochOrbitNum,&ephemerisType);
  1362.  
  1363.         /* if object number was specified on string 'str', readTle() comes    */
  1364.         /* back with the satellite name on the same variable 'str'            */
  1365.  
  1366.         strcpy(stsStr,str);      /* need to restore satTypeFlag, since object */
  1367.         upperCase(stsStr);       /* number might have been specified          */
  1368.                               
  1369.         satTypeFlag = BASIC;
  1370.  
  1371.         if (!strncmp(stsStr,"STS",3))
  1372.             satTypeFlag = STS;
  1373.  
  1374.         if (!strncmp(stsStr,"MIR",3) && (int) strlen(stsStr) == 3)
  1375.             satTypeFlag = MIR;
  1376.  
  1377.         if (error)
  1378.         {
  1379.             doBeep(); reverseBlink(); nl();
  1380.  
  1381.             if (error == 1 || error == 2)
  1382.                 printf(" %s: check sum error in TLE set, line %d ",str,error);
  1383.  
  1384.             if (error == 3)
  1385.                 printf(" %s: no matching satellite name or object number ",str);
  1386.  
  1387.             if (error == 4)
  1388.                 printf(" %s: multiple entries ",str);
  1389.  
  1390.             nl(); normal(); nl();
  1391.  
  1392.             grandError++;
  1393.         }
  1394.  
  1395.         else
  1396.         {
  1397.             getSatModes(&satel[i].satelName[0]);
  1398.             changeElementUnits();
  1399.             getSatPrecession();
  1400.             checkPropModelType();
  1401.  
  1402.             strcpy(sat[n].satellite,str);
  1403.             strcpy(sat[n].satelliteAlias,satAlias);
  1404.             strcpy(sat[n].model,propModel);
  1405.  
  1406.             sat[n].satIdNum     = satNum;
  1407.             sat[n].elSet        = elementSet;
  1408.  
  1409.             sat[n].epDay        = epochDay;
  1410.             sat[n].elSetEp      = elsetEpoch;
  1411.             sat[n].launchEp     = launchEpoch;
  1412.  
  1413.             sat[n].epInc        = inclination;
  1414.             sat[n].epRaan       = epochRaan;
  1415.             sat[n].epEcc        = eccentricity;
  1416.             sat[n].epArgPer     = epochArgPerigee;
  1417.             sat[n].epMeanAnom   = epochMeanAnomaly;
  1418.             sat[n].epMeanMot    = epochMeanMotion;
  1419.             sat[n].epDecRate    = decayRate;
  1420.             sat[n].epDecRateDot = decayRateDot;
  1421.             sat[n].epBstar      = bStarCoeff;
  1422.             sat[n].epOrbNum     = epochOrbitNum;
  1423.             sat[n].ephType      = ephemerisType;
  1424.             sat[n].modelType    = propModelType;
  1425.  
  1426.             sat[n].dwnlnkFrq    = downlinkFreq;
  1427.             sat[n].uplnkFrq     = uplinkFreq;
  1428.             sat[n].perigPh      = perigeePhase;
  1429.             sat[n].maxPh        = maxPhase;
  1430.             sat[n].numFr        = numFreqs;
  1431.             sat[n].numMd        = numModes;
  1432.             sat[n].attitudeFl   = attitudeFlag;
  1433.             sat[n].attLtd       = attLat;
  1434.             sat[n].attLng       = attLong;
  1435.             sat[n].attX         = satAttGl[0];
  1436.             sat[n].attY         = satAttGl[1];
  1437.             sat[n].attZ         = satAttGl[2];
  1438.             
  1439.             sat[n].semiMajAxis  = semiMajorAxis;
  1440.             sat[n].raanPr       = raanPrec;
  1441.             sat[n].periPr       = perigeePrec;
  1442.             sat[n].refOrb       = refOrbit;
  1443.  
  1444.             sat[n].cosInc       = cosInclination;
  1445.             sat[n].sinInc       = sinInclination;
  1446.  
  1447.             sat[n].satTypeFl    = satTypeFlag;
  1448.             sat[n].launchFl     = launchFlag;
  1449.             sat[n].prelaunchFl  = FALSE;
  1450.             sat[n].preorbitFl   = FALSE;
  1451.             sat[n].geosyncFl    = geoSyncFlag;
  1452.             sat[n].crashFl      = satCrashFlag;
  1453.  
  1454.             sat[n].statusFl     = (satNumSelect == satNum) ? 
  1455.                                    SELECT : FALSE;
  1456.  
  1457.             if (numFreqs)
  1458.             {
  1459.                 for (j = 0; j < numFreqs; j++)
  1460.                 {
  1461.                     strcpy(sat[n].satFreqs[j].downlinkMode,
  1462.                            freqs[j].downlinkMode);
  1463.                     strcpy(sat[n].satFreqs[j].uplinkMode,
  1464.                            freqs[j].uplinkMode);
  1465.                     sat[n].satFreqs[j].downlink  = freqs[j].downlink; 
  1466.                     sat[n].satFreqs[j].uplink    = freqs[j].uplink;
  1467.                     sat[n].satFreqs[j].bandwidth = freqs[j].bandwidth;
  1468.                     sat[n].satFreqs[j].sign      = freqs[j].sign;
  1469.                 }
  1470.             }
  1471.  
  1472.             if (numModes)
  1473.             {
  1474.                 for (j = 0; j < numModes; j++)
  1475.                 {
  1476.                     strcpy(sat[n].satModes[j].modeStr,modes[j].modeStr);
  1477.                     sat[n].satModes[j].minPhase = modes[j].minPhase; 
  1478.                     sat[n].satModes[j].maxPhase = modes[j].maxPhase;
  1479.                 }
  1480.             }
  1481.  
  1482.             n++;
  1483.         }
  1484.     }
  1485.  
  1486.     numSats = n;
  1487.  
  1488.     if (grandError)
  1489.     {
  1490.         printf("\nhit RETURN to continue ");
  1491.         mGets(str,80,stdin);
  1492.     }
  1493.  
  1494.     return;
  1495. }
  1496.  
  1497. /******************************************************************************/
  1498. /*                                                                            */
  1499. /* printElements: prints orbital elements                                     */
  1500. /*                                                                            */
  1501. /******************************************************************************/
  1502.  
  1503. void printElements()
  1504.  
  1505. {
  1506.     nl();
  1507.     printf("Satellite name    : %20s\n",satName);
  1508.     printf("Satellite number  : %20ld\n",satNum);
  1509.     printf("Element set       : %20d\n",elementSet);
  1510.     printf("Ephemeris type    : %20d\n",ephemerisType);
  1511.     printf("Epoch             : %20.9f d        ",elsetEpochDay);
  1512.     printf("%s\n",epochString);
  1513.     printf("Mean anomaly      : %20.9f deg\n",epochMeanAnomaly * CRD);
  1514.     printf("Arg of perigee    : %20.9f deg\n",epochArgPerigee * CRD);
  1515.     printf("RAAN              : %20.9f deg\n",epochRaan * CRD);
  1516.     printf("Inclination       : %20.9f deg\n",inclination * CRD);
  1517.     printf("Eccentricity      : %20.9f\n",eccentricity);
  1518.     printf("Semimajor axis    : %20.9f km\n",semiMajorAxis);
  1519.     printf("Perigee height    : %20.9f km\n",perigeeHeight);
  1520.     printf("Apogee height     : %20.9f km\n",apogeeHeight);
  1521.     printf("Mean motion       : %20.9f rev/d\n",epochMeanMotion);
  1522.     printf("Decay rate        : %20.9f rev/d^2\n",decayRate);
  1523.     printf("Decay rate dot    : %20.9f rev/d^3\n",decayRateDot);
  1524.     printf("BSTAR drag coeff. : %20.9f\n",bStarCoeff);
  1525.     printf("Orbit             : %20ld\n",epochOrbitNum);
  1526.     printf("Propagation model : %20s\n",propModel);
  1527.     nl();
  1528.  
  1529.     return;
  1530. }
  1531.  
  1532. /******************************************************************************/
  1533. /*                                                                            */
  1534. /* End of function block satread.c                                            */
  1535. /*                                                                            */
  1536. /******************************************************************************/
  1537.